#ifndef MYTYPE_H
#define MYTYPE_H

#ifdef __cplusplus
extern "C"
{
#endif

#include "stdint.h"
#include "stddef.h"
#include "micro_fun.h"
#include "micro_num.h"

#ifndef bbool
#define bbool uint8_t
#endif

#ifdef UINT_GEN
	typedef unsigned char uint8, UINT8;
	typedef unsigned short uint16, UINT16;
	typedef unsigned long uint32, UINT32;
	typedef unsigned long long uint64, UINT64;
	typedef signed char int8, INT8;
	typedef signed short int16, INT16;
	typedef signed long int32, INT32;
	typedef signed long long int64, INT64;
#endif

#ifdef BYTE_GEN
	typedef unsigned char byte, BYTE;
	typedef unsigned short word, WORD;
	typedef unsigned long dword, DWORD;
	typedef unsigned long long qword, QWORD;
	typedef signed char ibyte, IBYTE;
	typedef signed short iword, IWORD;
	typedef signed long idword, IDWORD;
	typedef signed long long iqword, IQWORD;
#endif

#ifdef UCHAR_GEN
	typedef unsigned char uchar, UCHAR;
	typedef unsigned short ushort, USHORT;
	typedef unsigned long ulong, ULONG;
	typedef unsigned long long ullong, ULLONG;

	typedef signed char ichar, ICHAR;
	typedef signed short ishort, ISHORT;
	typedef signed long ilong, ILONG;
	typedef signed long long illong, ILLONG;

	typedef unsigned int uint, UINT;
#endif

#ifdef U8_GEN
	typedef unsigned char u8, U8;
	typedef unsigned short u16, U16;
	typedef unsigned long u32, U32;
	typedef unsigned long long u64, U64;

	typedef signed char i8, I8, s8, S8;
	typedef signed short i16, I16, s16, S16;
	typedef signed long i32, I32, s32, S32;
	typedef signed long long i64, I64, s64, S64;

	typedef volatile unsigned char uv8, vu8, UV8, VU8;
	typedef volatile unsigned short uv16, vu16, UV16, VU16;
	typedef volatile unsigned long uv32, vu32, UV32, VU32;
	typedef volatile unsigned long long uv64, vu64, UV64, VU64;

	typedef volatile signed char iv8, vi8, IV8, VI8, sv8, vs8, SV8, VS8;
	typedef volatile signed short iv16, vi16, IV16, VI16, sv16, vs16, SV16, VS16;
	typedef volatile signed long iv32, vi32, IV32, VI32, sv32, vs32, SV32, VS32;
	typedef volatile signed long long iv64, vi64, IV64, VI64, sv64, vs64, SV64, VS64;

	typedef const unsigned char uc8, cu8, UC8, CU8;
	typedef const unsigned short uc16, cu16, UC16, CU16;
	typedef const unsigned long uc32, cu32, UC32, CU32;
	typedef const unsigned long long uc64, cu64, UC64, CU64;

	typedef const signed char ic8, ci8, IC8, CI8, sc8, cs8, SC8, CS8;
	typedef const signed short ic16, ci16, IC16, CI16, sc16, cs16, SC16, CS16;
	typedef const signed long ic32, ci32, IC32, CI32, sc32, cs32, SC32, CS32;
	typedef const signed long long ic64, ci64, IC64, CI64, sc64, cs64, SC64, CS64;
#endif

	typedef unsigned char u08, U08;
	typedef signed char i08, I08, s08, S08;
	typedef volatile unsigned char uv08, vu08, UV08, VU08;
	typedef volatile signed char iv08, vi08, IV08, VI08, sv08, vs08, SV08, VS08;
	typedef const unsigned char uc08, cu08, UC08, CU08;
	typedef const signed char ic08, ci08, IC08, CI08, sc08, cs08, SC08, CS08;

	typedef unsigned char uu8, UU8, uu08, UU08;
	typedef unsigned short uu16, UU16;
	typedef unsigned long uu32, UU32;
	typedef unsigned long long uu64, UU64;

	typedef signed char ii8, II8, ss8, SS8, ii08, II08, ss08, SS08;
	typedef signed short ii16, II16, ss16, SS16;
	typedef signed long ii32, II32, ss32, SS32;
	typedef signed long long ii64, II64, ss64, SS64;

	typedef volatile unsigned char uuv8, vuu8, UUV8, VUU8, uuv08, vuu08, UUV08, VUU08;
	typedef volatile unsigned short uuv16, vuu16, UUV16, VUU16;
	typedef volatile unsigned long uuv32, vuu32, UUV32, VUU32;
	typedef volatile unsigned long long uuv64, vuu64, UUV64, VUU64;

	typedef volatile signed char iiv8, vii8, IIV8, VII8, iiv08, vii08, IIV08, VII08;
	typedef volatile signed short iiv16, vii16, IIV16, VII16;
	typedef volatile signed long iiv32, vii32, IIV32, VII32;
	typedef volatile signed long long iiv64, vii64, IIV64, VII64;

	typedef volatile signed char ssv8, vss8, SSV8, VSS8, ssv08, vss08, SSV08, VSS08;
	typedef volatile signed short ssv16, vss16, SSV16, VSS16;
	typedef volatile signed long ssv32, vss32, SSV32, VSS32;
	typedef volatile signed long long ssv64, vss64, SSV64, VSS64;

	typedef const unsigned char uuc8, cuu8, UUC8, CUU8;
	typedef const unsigned short uuc16, cuu16, UUC16, CUU16;
	typedef const unsigned long uuc32, cuu32, UUC32, CUU32;
	typedef const unsigned long long uuc64, cuu64, UUC64, CUU64;

	typedef const signed char iic8, cii8, IIC8, CII8, iic08, cii08, IIC08, CII08;
	typedef const signed short iic16, cii16, IIC16, CII16;
	typedef const signed long iic32, cii32, IIC32, CII32;
	typedef const signed long long iic64, cii64, IIC64, CII64;

	typedef const signed char ssc8, css8, SSC8, CSS8, ssc08, css08, SSC08, CSS08;
	typedef const signed short ssc16, css16, SSC16, CSS16;
	typedef const signed long ssc32, css32, SSC32, CSS32;
	typedef const signed long long ssc64, css64, SSC64, CSS64;

	typedef unsigned int uwcpu;
	typedef signed int swcpu;

#define vfun(fun) ((void (*)(void))(fun))
#define vfun_vp(fun) ((void (*)(void *))(fun))
#define ifun(fun) ((int (*)(void))(fun))
#define ifun_vp(fun) ((int (*)(void *))(fun))
#define vfun_i32(fun) ((void (*)(i32))(fun))
#define vfun_i16(fun) ((void (*)(i16))(fun))
#define vfun_i8(fun) ((void (*)(i8))(fun))

#define def_vfun(fun) void (*fun)(void)
#define def_vfun_vp(fun) void (*fun)(void *)
#define def_ifun(fun) int (*fun)(void)
#define def_ifun_vp(fun) int (*fun)(void *)
#define def_vfun_i32(fun) void (*fun)(i32)
#define def_vfun_i32(fun) void (*fun)(i32)

#define convert_arr_ptr(ptr, type, len) (type(*)[len])(ptr)
#define convert_plane_ptr(ptr, type, m, n) (type(*)[m][n])(ptr)

#define def_arr_ptr(ptr, type, len) type(*ptr)[len]
#define def_plane_ptr(ptr, type, m, n) type(*ptr)[m][n]

#define def_nplane_ptr(ptr, x, type, m, n) type(*ptr[x])[m][n]

#ifndef ext_inrom
#define ext_inrom const
#endif

#ifndef ext_code
#define ext_code const
#endif

#define i8p(x) ((ii8 *)(x))
#define i16p(x) ((ii16 *)(x))
#define i32p(x) ((ii32 *)(x))
#define i64p(x) ((ii64 *)(x))
#define u8p(x) ((uu8 *)(x))
#define u16p(x) ((uu16 *)(x))
#define u32p(x) ((uu32 *)(x))
#define u64p(x) ((uu64 *)(x))

#define vi8p(x) ((volatile ii8 *)(x))
#define vi16p(x) ((volatile ii16 *)(x))
#define vi32p(x) ((volatile ii32 *)(x))
#define vi64p(x) ((volatile ii64 *)(x))
#define vu8p(x) ((volatile uu8 *)(x))
#define vu16p(x) ((volatile uu16 *)(x))
#define vu32p(x) ((volatile uu32 *)(x))
#define vu64p(x) ((volatile uu64 *)(x))

#define LIMITE_STR_DEF
	typedef struct
	{
		ii8 min;
		ii8 max;
	} i8_limit_type;

	typedef struct
	{
		ii16 min;
		ii16 max;
	} i16_limit_type;

	typedef struct
	{
		ii32 min;
		ii32 max;
	} i32_limit_type;

#define DATA_SPLIT_DEF
	typedef union
	{
		uint8_t Val;
		uint8_t uVal;
		int8_t iVal;
		uint8_t uval;
		int8_t ival;
		struct
		{
			uint8_t b0 : 1;
			uint8_t b1 : 1;
			uint8_t b2 : 1;
			uint8_t b3 : 1;
			uint8_t b4 : 1;
			uint8_t b5 : 1;
			uint8_t b6 : 1;
			uint8_t b7 : 1;
		} bits;
	} UINT8_VAL, UINT8_BITS;

	typedef union
	{
		uint16_t Val;
		uint16_t uVal;
		int16_t iVal;
		uint16_t uval;
		int16_t ival;
		uint8_t v[2];
		struct
		{
#ifndef BIG_ENDIAN
			uint8_t LB;
			uint8_t HB;
#else
		uint8_t HB;
		uint8_t LB;
#endif
		} byte;

		struct
		{
			uint16_t b0 : 1;
			uint16_t b1 : 1;
			uint16_t b2 : 1;
			uint16_t b3 : 1;
			uint16_t b4 : 1;
			uint16_t b5 : 1;
			uint16_t b6 : 1;
			uint16_t b7 : 1;
			uint16_t b8 : 1;
			uint16_t b9 : 1;
			uint16_t b10 : 1;
			uint16_t b11 : 1;
			uint16_t b12 : 1;
			uint16_t b13 : 1;
			uint16_t b14 : 1;
			uint16_t b15 : 1;
		} bits;
	} UINT16_VAL, UINT16_BITS;

	typedef union
	{
		uint32_t Val;
		uint32_t uVal;
		int32_t iVal;
		uint32_t uval;
		int32_t ival;
		uint16_t w[2];
		uint8_t v[4];

		struct
		{
#ifndef BIG_ENDIAN
			uint8_t LB;
			uint8_t HB;
			uint8_t UB;
			uint8_t MB;
#else
		uint8_t MB;
		uint8_t UB;
		uint8_t HB;
		uint8_t LB;
#endif
		} byte;

		struct
		{
#ifndef BIG_ENDIAN
			uint16_t LW;
			uint16_t HW;
#else
		uint16_t HW;
		uint16_t LW;
#endif
		} word;

		struct
		{
			uint32_t b0 : 1;
			uint32_t b1 : 1;
			uint32_t b2 : 1;
			uint32_t b3 : 1;
			uint32_t b4 : 1;
			uint32_t b5 : 1;
			uint32_t b6 : 1;
			uint32_t b7 : 1;
			uint32_t b8 : 1;
			uint32_t b9 : 1;
			uint32_t b10 : 1;
			uint32_t b11 : 1;
			uint32_t b12 : 1;
			uint32_t b13 : 1;
			uint32_t b14 : 1;
			uint32_t b15 : 1;
			uint32_t b16 : 1;
			uint32_t b17 : 1;
			uint32_t b18 : 1;
			uint32_t b19 : 1;
			uint32_t b20 : 1;
			uint32_t b21 : 1;
			uint32_t b22 : 1;
			uint32_t b23 : 1;
			uint32_t b24 : 1;
			uint32_t b25 : 1;
			uint32_t b26 : 1;
			uint32_t b27 : 1;
			uint32_t b28 : 1;
			uint32_t b29 : 1;
			uint32_t b30 : 1;
			uint32_t b31 : 1;
		} bits;
	} UINT32_VAL, UINT32_BITS;

	typedef union
	{
		uint8_t Val;
		uint8_t uVal;
		int8_t iVal;
		uint8_t uval;
		int8_t ival;
		struct
		{
			uint8_t b0 : 1;
			uint8_t b1 : 1;
			uint8_t b2 : 1;
			uint8_t b3 : 1;
			uint8_t b4 : 1;
			uint8_t b5 : 1;
			uint8_t b6 : 1;
			uint8_t b7 : 1;
		} bits;
	} BYTE_VAL, BYTE_BITS, byte_tt, BYTE_TT;

	typedef union
	{
		uint16_t Val;
		uint16_t uVal;
		int16_t iVal;
		uint16_t uval;
		int16_t ival;
		uint8_t v[2];
		struct
		{
#ifndef BIG_ENDIAN
			byte_tt LB;
			byte_tt HB;
#else
		byte_tt HB;
		byte_tt LB;
#endif
		} byte;

		struct
		{
			uint16_t b0 : 1;
			uint16_t b1 : 1;
			uint16_t b2 : 1;
			uint16_t b3 : 1;
			uint16_t b4 : 1;
			uint16_t b5 : 1;
			uint16_t b6 : 1;
			uint16_t b7 : 1;
			uint16_t b8 : 1;
			uint16_t b9 : 1;
			uint16_t b10 : 1;
			uint16_t b11 : 1;
			uint16_t b12 : 1;
			uint16_t b13 : 1;
			uint16_t b14 : 1;
			uint16_t b15 : 1;
		} bits;
	} WORD_VAL, WORD_BITS, word_tt, WORD_TT;

	typedef union
	{
		uint32_t Val;
		uint32_t uVal;
		int32_t iVal;
		uint32_t uval;
		int32_t ival;
		uint16_t w[2];
		uint8_t v[4];

		struct
		{
#ifndef BIG_ENDIAN
			byte_tt LB;
			byte_tt HB;
			byte_tt UB;
			byte_tt MB;
#else
		byte_tt MB;
		byte_tt UB;
		byte_tt HB;
		byte_tt LB;
#endif
		} byte;

		struct
		{
#ifndef BIG_ENDIAN
			word_tt LW;
			word_tt HW;
#else
		word_tt HW;
		word_tt LW;
#endif
		} word;

		struct
		{
			uint32_t b0 : 1;
			uint32_t b1 : 1;
			uint32_t b2 : 1;
			uint32_t b3 : 1;
			uint32_t b4 : 1;
			uint32_t b5 : 1;
			uint32_t b6 : 1;
			uint32_t b7 : 1;
			uint32_t b8 : 1;
			uint32_t b9 : 1;
			uint32_t b10 : 1;
			uint32_t b11 : 1;
			uint32_t b12 : 1;
			uint32_t b13 : 1;
			uint32_t b14 : 1;
			uint32_t b15 : 1;
			uint32_t b16 : 1;
			uint32_t b17 : 1;
			uint32_t b18 : 1;
			uint32_t b19 : 1;
			uint32_t b20 : 1;
			uint32_t b21 : 1;
			uint32_t b22 : 1;
			uint32_t b23 : 1;
			uint32_t b24 : 1;
			uint32_t b25 : 1;
			uint32_t b26 : 1;
			uint32_t b27 : 1;
			uint32_t b28 : 1;
			uint32_t b29 : 1;
			uint32_t b30 : 1;
			uint32_t b31 : 1;
		} bits;
	} DWORD_VAL, DWORD_BITS, dword_tt, DWORD_TT;

#ifndef U64_NONE
	typedef union
	{
		uint64_t Val;
		uint64_t uVal;
		int64_t iVal;
		uint64_t uval;
		int64_t ival;
		uint32_t dw[2];
		uint16_t w[4];
		uint8_t v[8];

		struct
		{
#ifndef BIG_ENDIAN
			word_tt LW;
			word_tt HW;
			word_tt UW;
			word_tt MW;
#else
			word_tt MW;
			word_tt UW;
			word_tt HW;
			word_tt LW;
#endif
		} word;

		struct
		{
#ifndef BIG_ENDIAN
			dword_tt LDW;
			dword_tt HDW;
#else
			dword_tt HDW;
			dword_tt LDW;
#endif
		} dword;
	} QWORD_VAL, QWORD_BITS, qword_tt, QWORD_TT;

#endif

#define uun_tt_gen
	typedef union
	{
		uu8 uval;
		ii8 ival;
	} u08_tt, U08TT;

	typedef union
	{
		uu16 uval;
		ii16 ival;
		u08_tt v[2];
		struct
		{
#ifndef BIG_ENDIAN
			u08_tt lb;
			u08_tt hb;
#else
		u08_tt hb;
		u08_tt lb;
#endif
		} byte;
	} u16_tt, U16TT;

	typedef union
	{
		float fval;
		uu32 uval;
		ii32 ival;
		u08_tt v[4];
		u16_tt w[2];
		struct
		{
#ifndef BIG_ENDIAN
			u16_tt lw;
			u16_tt hw;
#else
		u16_tt hw;
		u16_tt lw;
#endif
		} word;
		struct
		{
#ifndef BIG_ENDIAN
			u08_tt lb;
			u08_tt hb;
			u08_tt ub;
			u08_tt mb;
#else
		u08_tt mb;
		u08_tt ub;
		u08_tt hb;
		u08_tt lb;
#endif
		} byte;
	} u32_tt, U32TT;

#ifndef U64_NONE
	typedef union
	{
		uu64 uval;
		ii64 ival;
		u32_tt dw[2];
		u16_tt w[4];
		u08_tt v[8];
		struct
		{
#ifndef BIG_ENDIAN
			u16_tt lw;
			u16_tt hw;
			u16_tt uw;
			u16_tt mw;
#else
			u16_tt mw;
			u16_tt uw;
			u16_tt hw;
			u16_tt lw;
#endif
		} word;
		struct
		{
#ifndef BIG_ENDIAN
			u32_tt ldw;
			u32_tt hdw;
#else
			u32_tt hdw;
			u32_tt ldw;
#endif
		} dword;
	} u64_tt, U64TT;

#endif

#define LED_SEG_STRUCT
	typedef union
	{
		uint8_t val;
		struct
		{
			uint8_t A : 1;
			uint8_t B : 1;
			uint8_t C : 1;
			uint8_t D : 1;
			uint8_t E : 1;
			uint8_t F : 1;
			uint8_t G : 1;
			uint8_t DP : 1;
		} seg;
	} led_seg_type;

#ifdef __cplusplus
}
#endif

#endif 
